package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanPageDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "护理计划相关接口")
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult selectAll(){
    List<NursingPlanVO>  nursingPlanVOs = nursingPlanService.selectAll();
     return success(nursingPlanVOs);
    }
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult pageCondition(NursingPlanPageDto nursingPlanPageDto){
       PageResponse<NursingPlanVO> plans = nursingPlanService.pageCondition(nursingPlanPageDto);
        return success(plans);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理计划")
    public ResponseResult getById(@PathVariable Long id){
      NursingPlanVO nursingPlanVO =  nursingPlanService.getById(id);
      return  success(nursingPlanVO);
    }

    @PutMapping("/{id}")
    @ApiOperation("根据ID查询护理计划")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto,@PathVariable Long id){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return success();
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult insert(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.insert(nursingPlanDto);
        return success();
    }


    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改状态")
    public ResponseResult changeStatus(@PathVariable Long id , @PathVariable Integer status){
        nursingPlanService.changeStatus(id,status);
        return success();
    }

}
